<?php
$loader->requireOnce('includes/Datasource_sql.class.php');
class HourCoefficient extends ORDataObject {
	var $hour_coefficient_id	=	'';
	var $fee_coefficient_id		=	'';
  	var $hour_type				=	'';
  	var $value					=	'';
	
	var $_table					=	'hour_coefficient';
	var $_key					=	'hour_coefficient_id';
	var	$_internalName			=	'HourCoefficient';
	var $_foreignKeyList		=	array(
		'fee_coefficient_id'		=>	'fee_coefficient'
	);
	
	public function HourCoefficient(){
		parent::ORDataObject();
	}
	
	public function setup($id = 0){
		$this->set('id',$id);
		if($id>0){
			$this->populate();
		}
	}
	
	public function populate(){
		parent::populate('hour_coefficient_id');
	}
	
	public function setData($fee_coefficient_id, $hour_type, $value){
		$data	=	array(	
			'fee_coefficient_id'	=>	$fee_coefficient_id,
			'hour_type'				=>	$hour_type,
			'value'					=>	$value
		);
		$this->populateArray($data);
	}

	public function getCoefficientValues($empId = 0){
		$ds		=	&new Datasource_sql();
		$sql	=	array(
			'cols'		=>	"hc.fee_coefficient_id, hc.hour_type, hc.value",
			'from'		=>	"$this->_table hc INNER JOIN ".$this->_foreignKeyList['fee_coefficient_id'].
				" c ON hc.fee_coefficient_id=c.fee_coefficient_id",
			'where'		=>	"c.person_id=".(int)$empId,
			'order by'	=>	"c.fee_coefficient_id"
		);		
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function getRecordsByFeeCoefficientId($id){
		$ds		=	&new Datasource_sql();
		$sql	=	array(
			'cols'	=>	"hc.hour_coefficient_id, hc.fee_coefficient_id, hc.hour_type, hc.value",
			'from'	=>	"$this->_table hc",
			'where'	=>	"hc.fee_coefficient_id=".(int)$id
		);
		$ds->setup($this->_db, $sql);
		return $ds->toArray();
	}
	
	public function deleteRecordsByFeeCoefficientId($id){
		$sql	=	"DELETE FROM $this->_table WHERE  fee_coefficient_id=".(int)$id;
		$this->_execute($sql);
	}
	
    public function getRecordsByFeeCoefIds($ids) {
        $ds     =   &new Datasource_sql();
        $sql    =   array(
            'cols'  =>  "hc.hour_coefficient_id, hc.fee_coefficient_id, hc.hour_type, hc.value",
            'from'  =>  "$this->_table hc",
            'where' =>  "hc.fee_coefficient_id IN (" . $ids . ")"
        );
        $ds->setup($this->_db, $sql);
        return $ds->toArray();
    }
}
?>